home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / mcu11 / an1010.arc / EEPROGIX.ASC < prev    next >
Text File  |  1987-06-10  |  10KB  |  223 lines

  1. *************************************************************
  2. *             EEPROGIX.ASC 19/3/87     Revision 1.0         *
  3. *                                                           *
  4. * Written by R.Soja, Motorola, East Kilbride                *
  5. * Motorola Copyright 1987.                                  *
  6. *                                                           *
  7. *        This program loads S records from the host to      *
  8. * either a 2864 external EEPROM on the 68HC11 external bus, *
  9. * or to the 68HC11's internal EEPROM. It can also be used   *
  10. * verify memory contents against an S record file or just   *
  11. * load RAM located on the 68HC11's external bus.            *
  12. * Each byte loaded is echoed back to the host.              *
  13. * When programming a 2864, data polling is used to detect   *
  14. * completion of the programming cycle.                      *
  15. * As the host software always waits for the echo before     *
  16. * downloading the next byte, host transmission is suspended *
  17. * during the data polling period.                           *
  18. * Because the serial communication rate (~1mS/byte) is      *
  19. * slower than the 2864 internal timer timeout rate (~300uS) *
  20. * page write mode cannot be used. This means that data      *
  21. * polling is active on each byte written to the EEPROM,     *
  22. * after an initial delay of approx 500uS.                   *
  23. *                                                           *
  24. * When the internal EEPROM is programmed,instead of data    *
  25. * polling, each byte is verified after programming.         *
  26. * In this case, the 500uS delay is not required and is      *
  27. * bypassed.                                                 *
  28. * If a failure occurs, the program effectively hangs up. It *
  29. * is the responsibility of the host downloader program to   *
  30. * detect this condition and take remedial action.           *
  31. * The BASIC program EELOAD just displays a 'Communication   *
  32. * breakdown' message, and terminates the program.           *
  33. *                                                           *
  34. * When used in the verify mode, apart from the normal echo  *
  35. * back of each character, all differences between memory    *
  36. * and S record data are also sent back to the host.         *
  37. * The host software must be capable of detecting this, and  *
  38. * perform the action required.                              *
  39. * The BASIC loader program EELOAD simply displays the       *
  40. * returned erroneous byte adjacent to the expected byte,    *
  41. * separated by a colon.                                     *
  42. *                                                           *
  43. * Before receiving the S records, a code byte is received   *
  44. * from the host. i.e.:                                      *
  45. *                     ASCII 'X' for external EEPROM         *
  46. *                     ASCII 'I' for internal EEPROM         *
  47. *                     ASCII 'V' for verify EEPROM           *
  48. *                                                           *
  49. * This program is designed to be used with the BASIC EELOAD *
  50. * program.                                                  *
  51. * Data transfer is through the SCI, configured for 8 data   *
  52. * bits, 9600 baud.                                          *
  53. *                                                           *
  54. * Constants
  55. TDRE     EQU $80
  56. RDRF     EQU $20
  57. MDA      EQU $20
  58. SMOD     EQU $40
  59. mS10     EQU 10000/3         10mS delay with 8MHz xtal.
  60. uS500    EQU 500/3           500uS delay.
  61. *
  62. * Registers
  63. BAUD     EQU $2B
  64. SCCR1    EQU $2C
  65. SCCR2    EQU $2D
  66. SCSR     EQU $2E
  67. SCDR     EQU $2F
  68. PPROG    EQU $3B
  69. HPRIO    EQU $3C
  70. CONFIG   EQU $103F
  71. *
  72. * Variables. Note: They overwrite initialisation code!!!!
  73.          ORG $0
  74. EEOPT    RMB 1
  75. MASK     RMB 1
  76. TEMP     RMB 1
  77. LASTBYTE RMB 1
  78. *
  79. * Program
  80.          ORG $0
  81.          LDS #$FF
  82.          LDX #$1000          Offset for control registers.
  83.          CLR SCCR1,X         Initialise SCI for 8 data bits, 9600 baud
  84.          LDD #$300C
  85.          STAA BAUD,X
  86.          STAB SCCR2,X
  87.          BSET HPRIO,X,#MDA   Force Special Test mode first,
  88. *=>> MAINTAIN SPECIAL TEST MODE TO ALLOW B96D CONFIG REGISTER PROGRAMMING <<==
  89. *         BCLR HPRIO,X,#SMOD  and then expanded mode. (From Bootstrap mode)
  90. ReadOpt  STS <EEOPT          Default to internal EEPROM: EEOPT=0; MASK=$FF;
  91.          BSR READC           Then check control byte for external or internal
  92.          CMPB #'I'           EEPROM selection.
  93.          BEQ LOAD
  94.          CMPB #'X'           If external EEPROM requested
  95.          BNE OptVerf
  96.          INC EEOPT           then change option to 1
  97.          LDAA #$80
  98.          STAA <MASK          and select mask for data polling mode.
  99.          BRA LOAD
  100. *
  101. OptVerf  CMPB #'V'           If not verify then
  102.          BNE ReadOpt         get next character else
  103.          DEC EEOPT           make EEOPT flag negative.
  104. *
  105. LOAD     EQU *
  106.          BSR READC
  107.          CMPB #'S            Wait until S1 or S9 received,
  108.          BNE LOAD            discarding checksum of previous S1 record.
  109.          BSR READC
  110.          CMPB #'1
  111.          BEQ LOAD1
  112.          CMPB #'9
  113.          BNE LOAD
  114.          BSR RDBYTE          Complete reading S9 record before terminating
  115.          TBA
  116.          SUBA #2             # of bytes to read including checksum.
  117.          BSR GETADR          Get execution address in Y
  118. LOAD9    BSR RDBYTE          Now discard remaining bytes,
  119.          DECA                including checksum.
  120.          BNE LOAD9
  121.          CPY #0              If execution address =0 then
  122.          BEQ *               hang up else
  123.          JMP ,Y              jump to it!
  124. *
  125. LOAD1    EQU *
  126.          BSR RDBYTE          Read byte count of S1 record into ACCB
  127.          TBA                 and store in ACCA
  128.          SUBA #3             Remove load address & checksum bytes from count
  129.          BSR GETADR          Get load address into X register.
  130.          DEY                 Adjust it for first time thru' LOAD2 loop.
  131.          BRA LOAD1B
  132. *
  133. LOAD1A   LDAB EEOPT          Update CC register
  134.          BMI VERIFY          If not verifying EEPROM then
  135.          BEQ DATAPOLL        If programming external EEPROM
  136.          LDAB #uS500
  137. WAIT1    DECB                then wait 500uS max.
  138.          BNE WAIT1
  139. DATAPOLL LDAB ,Y             Now either wait for completion of programming
  140.          EORB <LASTBYTE      cycle by testing MS bit of last data written to
  141.          ANDB <MASK          memory or just verify internal programmed data.
  142.          BNE DATAPOLL
  143. LOAD1E   DECA                When all bytes done,
  144.          BEQ LOAD            get next S record (discarding checksum) else
  145. LOAD1B   BSR RDBYTE          read next data byte into ACCB.
  146.          INY                 Advance to next load address
  147.          TST EEOPT
  148.          BMI LOAD1D          If verifying, then don't program byte!
  149.          BEQ PROG            If internal EEPROM option selected then program
  150.          STAB ,Y             else just store byte at address.
  151. LOAD1D   STAB <LASTBYTE      Save it for DATA POLLING operation.
  152.          BRA LOAD1A
  153. *
  154. VERIFY   LDAB ,Y             If programmed byte
  155.          CMPB <LASTBYTE      is correct then
  156.          BEQ LOAD1E          read next byte
  157.          BSR WRITEC          else send bad byte back to host
  158.          BRA LOAD1E          before reading next byte.
  159. *
  160. READC    EQU *               ACCA, X, Y regs unchanged by this routine.
  161.          BRCLR SCSR,X,#RDRF,*
  162.          LDAB SCDR,X         Read next char
  163. WRITEC   BRCLR SCSR,X,#TDRE,*
  164.          STAB SCDR,X         and echo it back to host.
  165.          RTS                 Return with char in ACCB.
  166. *
  167. RDBYTE   BSR READC           1st read MS nibble
  168.          BSR HEXBIN          Convert to binary
  169.          LSLB                and move to upper nibble
  170.          LSLB
  171.          LSLB
  172.          LSLB
  173.          STAB <TEMP
  174.          BSR READC           Get ASCII char in ACCB
  175.          BSR HEXBIN
  176.          ORAB <TEMP
  177.          RTS                 Return with byte in ACCB
  178. *
  179. GETADR   EQU *
  180.          PSHA                Save byte counter
  181.          BSR RDBYTE          Read MS byte of address
  182.          TBA                 and put it in MS byte of ACCD
  183.          BSR RDBYTE          Now read LS byte of address into LS byte of ACCD
  184.          XGDY                Put load address in Y
  185.          PULA                Restore byte counter
  186.          RTS                 and return.
  187. *
  188. HEXBIN   EQU *
  189.          CMPB #'9            If ACCB>9 then assume its A-F
  190.          BLS HEXNUM
  191.          ADDB #9
  192. HEXNUM   ANDB #$F
  193.          RTS
  194. *
  195. PROG     EQU *
  196.          PSHA                Save ACCA.
  197.          LDAA #$16           Default to byte erase mode
  198.          CPY #CONFIG         If byte's address is CONFIG then use
  199.          BNE PROGA
  200.          LDAA #$06           bulk erase, to allow for A1 & A8 as well as A2.
  201. PROGA    BSR PROGRAM         Now erase byte, or entire memory + CONFIG.
  202.          LDAA #2
  203.          BSR PROGRAM         Now program byte.
  204.          CPY #CONFIG         If byte was CONFIG register then
  205.          BNE PROGX
  206.          LDAB ,Y             load ACCB with old value,to prevent hangup later.
  207. PROGX    PULA                Restore ACCA
  208.          BRA LOAD1D          and return to main bit.
  209. *
  210. PROGRAM  EQU *
  211.          STAA PPROG,X        Enable internal addr/data latches.
  212.          STAB ,Y             Write to required address
  213.          INC PPROG,X         Enable internal programming voltage
  214.          PSHX
  215.          LDX #mS10           and wait 10mS
  216. WAIT2    DEX
  217.          BNE WAIT2
  218.          PULX
  219.          DEC PPROG,X         Disable internal programming voltage
  220.          CLR PPROG,X         Release internal addr/data latches
  221.          RTS                 and return
  222. *
  223.          END